home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 271 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: clamage@Eng.sun.com (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: The type of the this pointer
  5. Date: 4 Feb 1996 00:50:42 GMT
  6. Organization: Sun Microsystems Inc., Mountain View, CA
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4f0vd7$ma6@engnews1.Eng.Sun.COM>
  9. References: <199602022342.SAA23370@cnj.digex.net>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Content-Type: text
  12. X-Nntp-Posting-Host: taumet.eng.sun.com
  13. X-Newsreader: NN version 6.5.0 #21 (NOV)
  14. Content-Length: 1730
  15. Originator: clamage@taumet
  16.  
  17. Dawn Koffman <dkoffman@cnj.digex.net> writes:
  18.  
  19. >Question 1 
  20.  
  21. >The ARM says:
  22.  
  23. >    "The type of this in a member function of class X is X *const unless 
  24. >     the member function is declared const or volatile; in those cases, 
  25. >     the type of this is const X *const and volatile X *const, respectively."
  26.  
  27. >9.4.2 of the 4/95 draft standard says:
  28.  
  29. >    "The type of this in a member function of class X is X*.  If the member
  30. >     function is declared const, the type of this is const X*, if the member
  31. >     function is declared volatile, the type of this is volatile X*, and
  32. >     if the member function is declared const volatile, the type of this 
  33. >     is const volatile X*."
  34.  
  35. >Why has the type of this changed from X* const to X*, and from const X* const 
  36. >to const X*?
  37.  
  38.  
  39. The draft also says "this" is a non-lvalue expression. Since "this"
  40. isn't an lvalue, const-ness is irrelevant. You can't assign to it or
  41. take its address, so const would have no effect for any operation you
  42. could perform. That is, const has a meaning only for lvalues.
  43.  
  44.  
  45. >Question 2
  46.  
  47. >9.4.2 of the draft standard goes on to say:
  48.  
  49. >    "In a const member function, the object for which the function is called 
  50. >     is accessed through a const access path; therefore, a const member 
  51. >     function shall not modify the object and its non-static data members."
  52.  
  53. >This section of the draft standard doesn't say anything to indicate that 
  54. >mutable data members may be modified inside const member functions.
  55.  
  56. The section on "mutable" (7.1.1) says it nullifies a const specifier
  57. on the containing object and that you may assign to the data member.
  58. It would be nice if the section on "this" mentioned "mutable".
  59. --
  60. Steve Clamage, stephen.clamage@eng.sun.com
  61.  
  62. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  63.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  64.   summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  65. ]
  66.